package com.example.springmall.exception;

import com.example.springmall.common.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(BusinessException.class)
    public R<Void> handleBusinessException(BusinessException e) {
        return R.error(e.getMessage());
    }

    @ExceptionHandler(UnauthorizedException.class)
    public R<Void> handleUnauthorizedException(UnauthorizedException e) {
        return R.unauthorized(e.getMessage());
    }

    @ExceptionHandler(ForbiddenException.class)
    public R<Void> handleForbiddenException(ForbiddenException e) {
        return R.forbidden(e.getMessage());
    }


    @ExceptionHandler(Exception.class)
    public R<Void> handleException(Exception e) {
        log.error("系统异常", e);
        return R.error("系统异常");
    }
} 